.equ PERSON_SIZE,76
.section .data
	str1:
		.string "请输入要找的名字>"
	str2:
		.string "%s"
	str3:
		.string "没找到呀\n"
	str4:
		.string "%-20s\t%-5s\t%-5s\t%-12s\t%-20s\n"
	str5:
		.string "名字"
	str6:
		.string "年龄"
	str7:
		.string "性别"
	str8:
		.string "电话"
	str9:
		.string "地址"
	str10:
		.string "%-20s\t%-5d\t%-5s\t%-12s\t%-20s\n"
.section .bss
    .lcomm fp,8
.section .text
.global SearchContact
.type SearchContact,@function
SearchContact:
	nop
	push %rbp
	mov %rsp,%rbp
	sub $24,%rsp
	mov %rdi,-8(%rbp)
#在堆区开辟一块空间接收用户输入
	mov $str1,%rdi
	mov $0,%rax
	call printf
	mov $0,%rax
	mov $20,%rdi
	call malloc
	test %rax,%rax
	movq %rax,fp
	movq fp,%r12
	js 0f
	je 0f
	mov $str2,%rdi
	mov %r12,%rsi
	call scanf
#调用查找函数
	movq -8(%rbp),%rdi
	movq %r12,%rsi
	call FindByName	
	cmp $-1,%rax
#返回-1说明没找到
	je 1f
#将返回结果存储起来
	mov %eax,-12(%rbp) #ret	
	mov $0,%rax
#打印基本信息
	mov $str4,%rdi
	mov $str5,%rsi
	mov $str6,%rdx
	mov $str7,%rcx
	mov $str8,%r8
	mov $str9,%r9
	call printf
	mov -8(%rbp),%rbx
	mov -12(%rbp),%eax
#找到联系人所在堆内存首地址
	imull $PERSON_SIZE,%eax
	movq (%rbx),%r12
	cltq
	addq %rax,%r12
	mov $str10,%rdi
#名字地址
	movq %r12,%rsi
	movl 20(%r12),%edx
	leaq 24(%r12),%rcx
	leaq 34(%r12),%r8
	leaq 46(%r12),%r9	
	mov $0,%rax
	call printf
#释放堆区内存
	mov fp,%rdi
    call free
	leaveq 
	retq
0:
	leaveq
	retq
1:
	mov $0,%rax
	mov $str3,%rdi
	call printf
	mov %r12,%rdi
	call free
	leaveq 
	retq
